import requests

# 配置信息
DEEPSEEK_API_KEY = "sk-cbe4b544a4e144c796c52ea631c366d0"  # 替换为你的API密钥
API_URL = "https://api.deepseek.com/v1/chat/completions"  # 确认实际API地址

# 请求头
headers = {
    "Authorization": f"Bearer {DEEPSEEK_API_KEY}",
    "Content-Type": "application/json"
}

# 请求数据
payload = {
    "model": "deepseek-chat",  # 根据文档选择模型
    "messages": [
        {"role": "user", "content": "你好，请介绍下自己"}
    ],
    "temperature": 0.7,
    "max_tokens": 500
}

try:
    # 发送POST请求
    response = requests.post(
        API_URL,
        headers=headers,
        json=payload,
        timeout=30
    )

    # 处理响应
    if response.status_code == 200:
        result = response.json()
        print(result['choices'][0]['message']['content'])
    else:
        print(f"请求失败，状态码：{response.status_code}")
        print(response.text)

except requests.exceptions.RequestException as e:
    print(f"请求异常: {e}")